home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
MenuHack
/
MenuHackSource.sit
/
MenuHack.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-21
|
6KB
|
220 lines
/*------------------------------------------------------------------------------
#
# MenuHack.c - C source for helper app for menu hack (handles bookmarks in
# Netscape, from an App, getting stuff from WebArranger. Yes, it's a cross-app patcher!
#
# Copyright © CE Software, Inc., Inc. 1996
# All rights reserved.
#
# This is pretty much just a basic shell. The heavy lifting is done in MHHandler.c
#
------------------------------------------------------------------------------*/
#include "MenuHackData.h" /* bring in all the #defines for MenuHack */
#include <PLStringFuncs.h> /* some special string handling stuff */
#include <string.h>
/* The "g" prefix is used to emphasize that a variable is global. */
/* GInBackground is maintained by our osEvent handling routines. Any part of
the program can check it to find out if it is currently in the background. */
Boolean gInBackground; /* maintained by Initialize and DoEvent */
Boolean gDoneFlag = true;
/* Here are declarations for all of the C routines. In MPW 3.0 and later we can use
actual prototypes for parameter type checking. */
void EventLoop( void );
void DoEvent( EventRecord *event );
void DoMenuCommand( long menuResult );
void Initialize( void );
/* Define HiWrd and LoWrd macros for efficiency. */
#define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
#define LoWrd(aLong) ((aLong) & 0xFFFF)
/* Define TopLeft and BotRight macros for convenience. Notice the implicit
dependency on the ordering of fields within a Rect */
#define TopLeft(aRect) (* (Point *) &(aRect).top)
#define BotRight(aRect) (* (Point *) &(aRect).bottom)
#pragma segment Main
main()
{
SetApplLimit(GetApplLimit()-32768); //give an additional 32K to stack
MaxApplZone(); /* expand the heap so code segments load at the top */
Initialize(); /* initialize the program */
InitWHandler();
EventLoop(); /* call the main event loop */
CloseWHandler();
}
/* Get events forever, and handle them by calling DoEvent.
Get the events by calling WaitNextEvent. */
void EventLoop()
{
RgnHandle cursorRgn;
Boolean gotEvent;
EventRecord event;
WindowPtr aWindow;
cursorRgn = NewRgn(); /* we’ll pass WNE an empty region the 1st time thru */
do {
gotEvent = WaitNextEvent(everyEvent, &event, 5, nil);
PollWHandler(event.where); // Call our routine that checks to see if some AppleEvent work is needed!
if ( gotEvent ) {
DoEvent(&event);
}
} while ( gDoneFlag );
gotEvent = true;
} /*EventLoop*/
/* Do the right thing for an event. Determine what kind of event it is, and call
the appropriate routines. */
void DoEvent(event)
EventRecord *event;
{
short part, err;
WindowPtr window;
Boolean hit;
char key;
Point aPoint;
switch ( event->what ) {
case kHighLevelEvent:
err = AEProcessAppleEvent( event ) ;
break;
case mouseDown:
part = FindWindow(event->where, &window);
switch ( part ) {
case inMenuBar: /* process a mouse menu command (if any) */
DoMenuCommand(MenuSelect(event->where));
break;
case inSysWindow: /* let the system handle the mouseDown */
SystemClick(event, window);
break;
}
break;
case keyDown:
case autoKey: /* check for menukey equivalents */
key = event->message & charCodeMask;
if ( event->modifiers & cmdKey ) /* Command key down */
if ( event->what == keyDown ) {
DoMenuCommand(MenuKey(key));
}
break;
case diskEvt:
if ( HiWord(event->message) != noErr ) {
SetPt(&aPoint, kDILeft, kDITop);
err = DIBadMount(aPoint, event->message);
}
break;
case kOSEvent:
switch ((event->message >> 24) & 0x0FF) { /* high byte of message */
case kSuspendResumeMessage: /* suspend/resume is also an activate/deactivate */
gInBackground = (event->message & kResumeMask) == 0;
break;
}
break;
}
} /*DoEvent*/
/* This is called when an item is chosen from the menu bar (after calling
MenuSelect or MenuKey). It performs the right operation for each command.
It is good to have both the result of MenuSelect and MenuKey go to
one routine like this to keep everything organized. */
void DoMenuCommand(menuResult)
long menuResult;
{
short menuID; /* the resource ID of the selected menu */
short menuItem; /* the item number of the selected menu */
short itemHit;
Str255 daName;
short daRefNum;
Boolean handledByDA;
menuID = HiWord(menuResult); /* use macros for efficiency to... */
menuItem = LoWord(menuResult); /* get menu item number and menu number */
switch ( menuID ) {
case mApple:
switch ( menuItem ) {
case iAbout: /* bring up alert for About */
itemHit = Alert(rAboutAlert, nil);
break;
default: /* all non-About items in this menu are DAs */
/* type Str255 is an array in MPW 3 */
GetItem(GetMHandle(mApple), menuItem, daName);
daRefNum = OpenDeskAcc(daName);
break;
}
break;
case mFile:
switch ( menuItem ) {
case iQuit:
gDoneFlag = false;
break;
}
break;
case mEdit: /* call SystemEdit for DA editing & MultiFinder */
handledByDA = SystemEdit(menuItem-1); /* since we don’t do any Editing */
break;
}
HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
} /*DoMenuCommand*/
void Initialize()
{
Handle menuBar;
WindowPtr window;
long total, contig;
EventRecord event;
short count;
long x;
OSErr err;
gInBackground = false;
InitGraf((Ptr) &qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
InstallAEHandlers();
menuBar = GetNewMBar(rMenuBar); /* read menus into menu bar */
if ( menuBar == nil ) ExitToShell();
SetMenuBar(menuBar); /* install menus */
DisposHandle(menuBar);
AddResMenu(GetMHandle(mApple), 'DRVR'); /* add DA names to Apple menu */
DrawMenuBar();
for (count = 1; count <= 3; count++)
{
if (WaitNextEvent(everyEvent, &event, 5, nil))
{
if (event.what==kHighLevelEvent)
{
err = AEProcessAppleEvent( &event ) ;
}
}
}
} /*Initialize*/